<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="com.gzgi.framework.*"%>
<%@ page import="com.gzgi.framework.util.*"%>
<%@ page import="com.gzgi.framework.context.*"%>
<%@ page import="com.gzgi.framework.lob.*"%>
<%@ page import="org.apache.commons.lang.StringUtils"%>
<%
    String fileId = request.getParameter("fileId");
	LobDataService lobDataService = (LobDataService) ContextFactory.getBean("lobDataService");
    LobData blob = null;
    if(StringUtils.isNotEmpty(fileId)){
	     blob = lobDataService.getLobData(fileId);
	}  
    if(blob != null && blob.getData() != null){
	  String filename = blob.getFilename();
	  try  {
		response.setContentType("application/octet-stream");
		response.setHeader("Content-Disposition", "attachment; filename="+filename);
		java.io.InputStream in = new BufferedInputStream(new ByteArrayInputStream(blob.getData() ));
		java.io.OutputStream outStream = response.getOutputStream();
		byte[] buf = new byte[1024];
		int bytes = 0;
		while((bytes = in.read(buf)) != -1) {
			outStream.write(buf, 0, bytes);
		}
		in.close();	
		outStream.close();	
	  }
	  catch(Throwable e) {
	  	System.out.println(e.toString());
		throw new ServletException(e.toString());
	  }
	}
%>